%div

  - if User.current.git_allowed_to?(:create_repository_protected_branches, @repository)
    .contextual= link_to l(:label_protected_branch_add), new_repository_protected_branch_path(@repository), class: 'icon icon-add modal-box'

  %h3
    = l(:label_protected_branches)
    = link_to "(#{l(:label_gitolite_documentation)})", 'http://gitolite.com/gitolite/conf.html#rules', target: '_blank'

  - if @repository_protected_branches.any?

    %table{ class: 'table table-hover',
            id: 'protected_branches',
            data: { 'update-url' => sort_repository_protected_branches_url },
            style: "opacity: #{@repository.protected_branches_enabled? ? '1' : '0.5'};" }
      %thead
        %tr
          %th
          %th= l(:label_permissions)
          %th= l(:label_branch_path)
          %th= l(:label_user_list)
          %th

      %tbody
        - @repository_protected_branches.each do |protected_branch|
          = content_tag_for(:tr, protected_branch) do
            %td
              %span{ class: 'handle' }
                [drag]

            %td
              - color = protected_branch.permissions == '-' ? 'important' : 'success'
              %span{ class: "label label-#{color}" }= protected_branch.permissions

            %td{ style: 'font-family: Consolas;' }= protected_branch.path

            %td= protected_branch.users.map { |u| link_to(u) }.join(', ').html_safe

            %td{ class: 'buttons' }
              - if User.current.git_allowed_to?(:edit_repository_protected_branches, @repository)
                = link_to l(:button_edit), edit_repository_protected_branch_path(@repository, protected_branch), class: 'icon icon-edit modal-box'
                = link_to l(:button_clone), clone_repository_protected_branch_path(@repository, protected_branch), class: 'icon icon-clone modal-box'
                = link_to l(:button_delete), repository_protected_branch_path(@repository, protected_branch), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'

    - if !@repository.protected_branches_enabled?
      %em= l(:protected_branches_reminder)

  - else
    %p{ class: 'nodata' }= l(:label_no_data)

:javascript
  $(document).ready(function() { setSortableElement('#protected_branches tbody', '#protected_branches'); });
